#!/usr/bin/env sh

set -e

export JAVA_HOME=/export/servers/jdk1.8.0_161
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/export/servers/hadoop-2.7.4
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export ZK_HOME=/export/servers/zookeeper-3.4.10
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZK_HOME/bin

case $1 in
"start"){
        for i in {"hadoop01","hadoop02","hadoop03"};
        do
                echo "-------启动 $i zookeeper-------"
                ssh $i "source /etc/profile;/export/servers/zookeeper-3.4.10/bin/zkServer.sh start"
        done
};;
"stop"){
        for h in {"hadoop01","hadoop02","hadoop03"};
        do
                echo "-------结束 $h zookeeper-------"
                ssh $h "source /etc/profile;/export/servers/zookeeper-3.4.10/bin/zkServer.sh stop"
        done
};;
"status"){
        for i in {"hadoop01","hadoop02","hadoop03"};
        do
                echo "-------角色 $i zookeeper-------"
                ssh $i "source /etc/profile;/export/servers/zookeeper-3.4.10/bin/zkServer.sh status"
        done
};;
esac
